﻿<div [@routerTransition]>

    <div class="m-subheader">
        <div class="row align-items-center">
            <div class="mr-auto col-auto">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{"Languages" | localize}}</span>
                </h3>
                <span class="m-section__sub">
                    {{"LanguagesHeaderInfo" | localize}}
                </span>
            </div>
            <div class="col text-right mt-3 mt-md-0">
                <button *ngIf="('Pages.Administration.Languages.Create' | permission) && multiTenancySideIsHost" (click)="createOrEditLanguageModal.show()" class="btn btn-primary"><i class="fa fa-plus"></i> {{"CreateNewLanguage" | localize}}</button>
            </div>
        </div>
    </div>

    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="row align-items-center">
                    <!--<Primeng-TurboTable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                        <p-table #dataTable
                                 (onLazyLoad)="getLanguages()"
                                 [value]="primengTableHelper.records"
                                 rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                                 [paginator]="false"
                                 [lazy]="true"
                                 [responsive]="primengTableHelper.isResponsive">
                            <ng-template pTemplate="header">
                                <tr>
                                    <th style="width: 130px"
                                        [hidden]="!isGrantedAny('Pages.Administration.Languages.Edit', 'Pages.Administration.Languages.ChangeTexts', 'Pages.Administration.Languages.Delete')">
                                        {{'Actions' | localize}}
                                    </th>
                                    <th>
                                        {{'Name' | localize}}
                                    </th>
                                    <th>
                                        {{'Code' | localize}}
                                    </th>
                                    <th *ngIf="appSession.tenantId ? true : false">
                                        {{'Default' | localize}} *
                                    </th>
                                    <th>
                                        {{'CreationTime' | localize}}
                                    </th>
                                    <th>
                                        {{'IsEnabled' | localize}}
                                    </th>
                                </tr>
                            </ng-template>
                            <ng-template pTemplate="body" let-record="$implicit">
                                <tr>
                                    <td style="width: 130px; text-align: center">
                                        <div class="btn-group dropdown" dropdown>
                                            <button dropdownToggle class="dropdown-toggle btn btn-sm btn-primary">
                                                <i class="fa fa-cog"></i><span class="caret"></span> {{"Actions" | localize}}
                                            </button>
                                            <ul class="dropdown-menu" *dropdownMenu>
                                                <li>
                                                    <a href="javascript:;" *ngIf="('Pages.Administration.Languages.Edit' | permission) && record.tenantId === appSession.tenantId"
                                                       (click)="createOrEditLanguageModal.show(record.id)">{{'Edit' | localize}}</a>
                                                </li>
                                                <li>
                                                    <a href="javascript:;" *ngIf="'Pages.Administration.Languages.ChangeTexts' | permission"
                                                       (click)="changeTexts(record)">{{'ChangeTexts' | localize}}</a>
                                                </li>
                                                <li>
                                                    <a href="javascript:;" *ngIf="'Pages.Administration.Languages.Edit' | permission"
                                                       (click)="setAsDefaultLanguage(record)">{{'SetAsDefaultLanguage' | localize}}</a>
                                                </li>
                                                <li>
                                                    <a href="javascript:;" *ngIf="('Pages.Administration.Languages.Delete' | permission) && record.tenantId === appSession.tenantId"
                                                       (click)="deleteLanguage(record)">{{'Delete' | localize}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{'Name' | localize}}</span>
                                        <span [ngClass]="{'text-bold' : defaultLanguageName === record.name}">
                                            <i [ngClass]="record.icon" class="margin-right-5"></i>
                                            {{record.displayName}} <span *ngIf="defaultLanguageName === record.name">({{'Default' | localize}})</span>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{'Code' | localize}}</span>
                                        {{record.name}}
                                    </td>
                                    <td *ngIf="appSession.tenantId ? true : false">
                                        <span class="ui-column-title">{{'Default' | localize}}</span>
                                        <span class="label m-badge m-badge--success m-badge--wide"
                                              *ngIf="record.tenantId !== appSession.tenantId">
                                            {{'Yes' | localize}}
                                        </span>
                                        <span class="label m-badge m-badge--metal m-badge--wide"
                                              *ngIf="record.tenantId === appSession.tenantId">
                                            {{'No' | localize}}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{'CreationTime' | localize}}</span>
                                        {{record.creationTime | momentFormat:'L'}}
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{'IsEnabled' | localize}}</span>
                                        <span class="label m-badge m-badge--success m-badge--wide"
                                              *ngIf="!record.isDisabled">
                                            {{'Yes' | localize}}
                                        </span>
                                        <span class="label m-badge m-badge--metal m-badge--wide"
                                              *ngIf="record.isDisabled">
                                            {{'No' | localize}}
                                        </span>
                                    </td>
                                </tr>
                            </ng-template>
                        </p-table>
                        <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                            {{'NoData' | localize}}
                        </div>
                        <div class="ui-table-footer">
                            {{'TotalRecordsCount' | localize:primengTableHelper.totalRecordsCount}}
                        </div>
                    </div>
                    <!--<Primeng-TurboTable-End>-->

                    <p class="margin-top-20" *ngIf="appSession.tenantId">
                        * {{"CanNotEditOrDeleteDefaultLanguages" | localize}}
                    </p>

                </div>
            </div>
        </div>
    </div>

    <createOrEditLanguageModal #createOrEditLanguageModal (modalSave)="getLanguages()"></createOrEditLanguageModal>
</div>
